//
//  CommunityTableViewController.m
//  NewChat
//
//  Created by 马欢 on 16/2/27.
//  Copyright © 2016年 蓝鸥. All rights reserved.
//

#import "CommunityTableViewController.h"
#import "CommunityTableViewCell.h"
#import "TopicTableViewController.h"
#import "ClickRightCornerJumpToViewController.h"


@interface CommunityTableViewController ()

//存放模块标题和简单介绍
@property(nonatomic,strong)NSArray *titleArray;
@property(nonatomic,strong)NSArray *introduceArray;
@property(nonatomic,strong)NSMutableArray*headerPictureArray;

@end

@implementation CommunityTableViewController

-(NSArray *)headerPictureArray{
    
    if (!_headerPictureArray) {
        
        _headerPictureArray = [NSMutableArray array];
    }
    return _headerPictureArray;
}

-(NSArray *)titleArray{
    if (!_titleArray) {
        _titleArray = [NSArray arrayWithObjects:@"热聊",@"唱歌",@"故事",@"心情",@"灌水",@"秘密", nil];
    }
    return _titleArray;
}

-(NSArray *)introduceArray{
    if (!_introduceArray) {
        
        _introduceArray = [NSArray arrayWithObjects:@"让热门的话题有你",@"让更多的人听到你",@"每个人都有自己的故事",@"此时的你，心情好吗",@"随便吹牛，聊聊人生", @"维多利亚的秘密",nil];
    }
    return _introduceArray;
}

-(instancetype)initWithStyle:(UITableViewStyle)style{
    
    if (self = [super initWithStyle:UITableViewStylePlain]) {
        
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    NSLog(@"这个页面是 社区--> CommunityTableViewController");
    //显示底部tabbar
    [self.tabBarController.tabBar setHidden:NO];
    self.navigationController.navigationBar.barTintColor = [UIColor greenColor];
}

-(void)viewWillDisappear:(BOOL)animated{
//    [self.tabBarController.tabBar setHidden:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor greenColor];
    NSLog(@"这个页面是 社区--> CommunityTableViewController");
    //设置标题
    self.navigationItem.title = @"社区";
    self.navigationController.navigationBar.backgroundColor = [UIColor greenColor];
    //设置右上方按钮
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"🔔" style:(UIBarButtonItemStylePlain) target:self action:@selector(clickRightBarAction:)];
    //注册cell
    [self.tableView registerClass:[CommunityTableViewCell class] forCellReuseIdentifier:@"Cell"];
    
    //去掉界面横线
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    //添加数据
    [self addData];
    
}

//添加数据
-(void)addData{
    
    for (int i  = 0; i < 6; i++) {
        
        NSString *picturePath = [NSString stringWithFormat:@"%d.jpg",i];
        [self.headerPictureArray addObject:picturePath];
    }
    
    
}


-(void)clickRightBarAction:(UIBarButtonItem*)sender{
    NSLog(@"点击右上角跳转");
   ClickRightCornerJumpToViewController *clickRightCornerJumpVC = [[ClickRightCornerJumpToViewController alloc]init];
   
   [self showViewController:clickRightCornerJumpVC sender:nil];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.headerPictureArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    return self.view.frame.size.height/7;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //cell的重用
    CommunityTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    //如果没有再创建cell
    if (!cell) {
        cell = [[CommunityTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];
    }
    
    cell.titleLbl.text = self.titleArray[indexPath.row];
    cell.introduceLbl.text = self.introduceArray[indexPath.row];
    NSString*path = [NSString stringWithFormat:@"%@",self.headerPictureArray[indexPath.row]];
    cell.imaV.image = [UIImage imageNamed:path];
    cell.numberLbl.text = @"16.90万";
    
    return cell;
}

//cell的点击事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSLog(@"你点击了CommunityTableViewController中的cell");
    TopicTableViewController *topVC = [[TopicTableViewController alloc]init];
    
    //把当前模块的标题传到下个页面
    topVC.aString = self.titleArray[indexPath.row];
    [self.navigationController pushViewController:topVC animated:YES];
    
    
}

@end
